/**
 * 
 */
package com.maohi.software.tupuna.ui;

import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JTabbedPane;

import com.maohi.software.tupuna.Page;

/**
 * @author heifara
 * 
 */
public class ContentUI extends JTabbedPane implements PropertyChangeListener {

	private static final long serialVersionUID = 1L;

	@Override
	public void addTab(String title, Component aComponent) {
		if (aComponent instanceof Page) {
			((Page) aComponent).addPropertyChangeListener(this);
		}

		super.addTab(title, aComponent);
	}

	@Override
	public void propertyChange(PropertyChangeEvent aEvent) {
		if (aEvent.getSource() instanceof Page && aEvent.getPropertyName().equals(Page.TITLE)) {
			int iIndex = this.indexOfComponent((Component) aEvent.getSource());
			this.setTitleAt(iIndex, (String) aEvent.getNewValue());
		}
	}
}
